
indiv_items <-
  estimation_data %>%
  select(ID, pre_post, validated_election_outcome, V_28, V_29, V_31_A, V_31_B, 
         V_32_A, V_32_B, V_32_C,
         V_17_A, V_17_C, V_17_D,
         V_17_F, V_17_G, V_17_H ) %>%
  pivot_longer(cols = c(V_28, V_29, V_31_A, V_31_B, 
                        V_32_A, V_32_B, V_32_C,
                        V_17_A, V_17_C, V_17_D,
                        V_17_F, V_17_G, V_17_H)) %>%
  group_by(name) %>%
  do(tidy(lm_robust(value ~ pre_post*validated_election_outcome, data = ., clusters = ID))) %>%
  filter(term == "pre_post:validated_election_outcomeNot Elected") %>%
  mutate(question = case_when(name == "V_28" ~ "Agree: The regional media is biased towards\nspecific candidates",
                              name == "V_29" ~ "Agree: The vote total reflects the will of the voters",
                              name == "V_31_A" ~ "Trust: Electoral commission (KPU)",
                              name == "V_31_B" ~ "Trust: General election supervisory committee\n(Bawaslu)",
                              name == "V_32_A" ~ "Agree: Compared to other forms of government,\nDemocracy is the best form for Indonesia",
                              name == "V_32_B" ~ "Agree: Democracy is the cause of\nthe chaos in our government",
                              name == "V_32_C" ~ "Agree: Democracy is the reason for our bad economy",
                              
                              name == "V_17_A" ~ "Dislike: Chinese",
                              name == "V_17_C" ~ "Dislike: Christians",
                              name == "V_17_D" ~ "Dislike: Muslims",
                              name == "V_17_F" ~ "Dislike: Supporters of Prabowo",
                              name == "V_17_G" ~ "Dislike: Supporters of Anies",
                              name == "V_17_H" ~ "Dislike: Supporters of Ganjar")) %>%
  mutate(family = case_when(name == "V_28" ~ "Trust in Elections",
                            name == "V_29" ~ "Trust in Elections",
                            name == "V_31_A" ~ "Trust in Elections",
                            name == "V_31_B" ~ "Trust in Elections",
                            name == "V_32_A" ~ "Support for Democracy",
                            name == "V_32_B" ~ "Support for Democracy",
                            name == "V_32_C" ~ "Support for Democracy",
                            
                            name == "V_17_A" ~ "Ethnic Animosity",
                            name == "V_17_C" ~ "Ethnic Animosity",
                            name == "V_17_D" ~ "Ethnic Animosity",
                            name == "V_17_F" ~ "Partisan Animosity",
                            name == "V_17_G" ~ "Partisan Animosity",
                            name == "V_17_H" ~ "Partisan Animosity"))


primary_indiv <-
  indiv_items %>%
  mutate(question = as.character(question)) %>%
  ggplot(aes(x=estimate, y = question)) +
  geom_point() +
  facet_col(family~., scales = "free") +
  geom_errorbarh(aes(xmin = estimate-(1.96*std.error), xmax = estimate + (1.96*std.error)), height = 0) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  theme_bw() +
  scale_color_manual(values = c("#B85042", "darkgrey")) +
  #ggtitle("Subset: Under 30 y.o.") +
  xlab("Estimated Effect of Losing (D-i-D)") +
  #ggtitle("Effect of Revealing Under/Over-Performance on Masculinism, Among Women") +
  theme(panel.grid.minor = element_blank(), 
        panel.grid.major.x = element_blank(),
        #axis.text.x = element_text(angle = 90),
        #axis.line.y.left = element_blank(),
        #strip.background = element_blank(),
        axis.line = element_line(colour = "black"),
        panel.border = element_blank(),
        axis.title.y = element_blank(), 
        legend.position = "bottom")



ggsave(filename = "./outputs/figures/figure_a10.pdf", plot = primary_indiv, width = 7, height = 6)
ggsave(filename = "./outputs/figures/figure_a10.eps", device = "eps", plot = primary_indiv, width = 7, height = 6)

